﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PagedList;
namespace Xwork.SEO.WebSite.Controllers
{
    /// <summary>
    /// 查看报表
    /// </summary>
    [UserAuthorize]
    public class ReportController : SEOController
    {
        //
        // GET: /Report/

        public ActionResult Index(int? siteId)
        {
            ViewData["engines"] = db.SearchEngines.OrderBy(p => p.ID).ToList();
            ViewData["siteId"] = new SelectList(db.SeoSites.OrderBy(p => p.ID).Where(p => p.UserID == User.ID).ToList(), "ID", "SiteUrl", siteId);
            return View(db.SeoKeywords.OrderBy(p => p.ID).ToPagedList(1, 20));
        }

        public ActionResult SeoLogs(int? pageIndex, long? siteId, long? keywordId)
        {
            IQueryable<SeoLog> q = db.SeoLogs.OrderByDescending(p => p.ID);
            if (siteId.HasValue)
            {
                q = q.Where(p => p.SeoKeyword.ID == siteId);
            }
            if (keywordId.HasValue)
            {
                q = q.Where(p => p.SeoKeywordID == keywordId);
            }
            return View(q.ToPagedList(pageIndex.HasValue ? pageIndex.Value : 1, 20));
        }
    }
}
